let oldPathMap = {
  '/zjkj/simulation/': [
    '/zjkj/simulation/subject_sw/',
    '/zjkj/simulation/subject_jjf/',
    '/zjkj/simulation/subject_cwgl/'
  ],
  '/zjkj/practice/': [
    '/zjkj/practice/subject_sw/',
    '/zjkj/practice/subject_jjf/',
    '/zjkj/practice/subject_cwgl/'
  ],
  '/zjkj/month/': [
    '/zjkj/month/subject_sw/',
    '/zjkj/month/subject_jjf/',
    '/zjkj/month/subject_cwgl/'],
  '/zjkj/keynote/': [
    '/zjkj/keynote/subject_sw/',
    '/zjkj/keynote/subject_jjf/',
    '/zjkj/keynote/subject_cwgl/'
  ],
  '/zjkj/exam/': [
    '/zjkj/information/sw/',
    '/zjkj/information/jjf/',
    '/zjkj/information/cwgl/',
    '/zjkj/exam/subject_sw/',
    '/zjkj/exam/subject_jjf/',
    '/zjkj/exam/subject_cwgl/'
  ],
  '/cta/simulation/':[
    '/cta/simulation/subject_sf1/',
    '/cta/simulation/subject_sf2/',
    '/cta/simulation/subject_ssfl/',
    '/cta/simulation/subject_sssw/',
    '/cta/simulation/subject_cwkj/',
  ],
  '/cta/keynote/':[
    '/cta/keynote/subject_sf1/',
    '/cta/keynote/subject_sf2/',
    '/cta/keynote/subject_ssfl/',
    '/cta/keynote/subject_sssw/',
    '/cta/keynote/subject_cwkj/'
  ],
  '/cta/exam/':[
    '/cta/information/sf1/',
    '/cta/information/sf2/',
    '/cta/information/ssfl/',
    '/cta/information/sssw/',
    '/cta/information/cwkj/',
    '/cta/exam/subject_sf1/',
    '/cta/exam/subject_sf2/',
    '/cta/exam/subject_ssfl/',
    '/cta/exam/subject_sssw/',
    '/cta/exam/subject_cwkj/',
  ],
  '/cta/chapter/':[
    '/cta/chapter/subject_sf1/',
    '/cta/chapter/subject_sf2/',
    '/cta/chapter/subject_ssfl/',
    '/cta/chapter/subject_sssw/',
    '/cta/chapter/subject_cwkj/'
  ],
  '/cpa/simulation/':[
    '/cpa/simulation/subject_sf/',
    '/cpa/simulation/subject_sj/',
    '/cpa/simulation/subject_jjf/',
    '/cpa/simulation/subject_cg/',
    '/cpa/simulation/subject_kj/',
    '/cpa/simulation/subject_zl/'
  ],
  '/cpa/keynote/':[
    '/cpa/keynote/subject_sf/',
    '/cpa/keynote/subject_sj/',
    '/cpa/keynote/subject_jjf/',
    '/cpa/keynote/subject_cg/',
    '/cpa/keynote/subject_kj/',
    '/cpa/keynote/subject_jjf/'
  ],
  '/cpa/exam/':[
    '/cpa/information/sf/',
    '/cpa/information/sj/',
    '/cpa/information/jjf/',
    '/cpa/information/cg/',
    '/cpa/information/kj/',
    '/cpa/information/zl/',
    '/cpa/exam/subject_sf/',
    '/cpa/exam/subject_sj/',
    '/cpa/exam/subject_jjf/',
    '/cpa/exam/subject_cg/',
    '/cpa/exam/subject_kj/',
    '/cpa/exam/subject_zl/',

  ],
  '/cpa/chapter/':[
    '/cpa/chapter/subject_sf/',
    '/cpa/chapter/subject_sj/',
    '/cpa/chapter/subject_jjf/',
    '/cpa/chapter/subject_cg/',
    '/cpa/chapter/subject_kj/',
    '/cpa/chapter/subject_jjf/'
  ],
  '/cjkj/simulation/':[
    '/cjkj/simulation/subject_sw/',
    '/cjkj/simulation/subject_jjf/',
   
  ],
  '/cjkj/month/':[
    '/cjkj/practice/subject_jjf/',
    '/cjkj/practice/subject_sw/',

  ],
  '/cjkj/keynote/':[
    '/cjkj/month/subject_sw/',
    '/cjkj/keynote/subject_jjf/'
  ],
  '/cjkj/exam/':[
    '/cjkj/information/sw/',
    '/cjkj/information/jjf/',
    '/cjkj/exam/subject_sw/',
    '/cjkj/exam/subject_jjf/',
    '/cjkj/chapter/subject_sw/',
    '/cjkj/chapter/subject_jjf/'
  ],
  '/': [
    '/index.html',
    '/cjkjPlan/',

  ],
  '/courses/4.html': [
    '/vplay/?course_id=32'
  ],
  '/personal/index.html': [
    '/news/personal/',
    '/personal/'
  ],
  '/newUserActivity.html': [
    '/free_try/'
  ]

}

let oldWebsitePathMap = {}
//此处代码优化下,提升性能
Object.keys(oldPathMap).forEach(item=>{
  let pathList = oldPathMap[item]
  pathList.forEach(subitem => {
    oldWebsitePathMap[subitem] = item
  });
})

module.exports = (req, res, next) => {
  let { protocol, path, headers: { host }, originalUrl } = req
  
  let redirectPath = oldWebsitePathMap[path] || ''
  // 考虑存在参数的情形（带?）
  if (originalUrl !== path) {
    redirectPath = oldWebsitePathMap[originalUrl]
  }
  if (redirectPath) {  //如果有重定向的路径,则重定向到此路径
    res.location(protocol+'://' + host + redirectPath) 
    res.statusCode =301
    res.end()
    return
  }
  next()
}